package partes_GUI;
import java.awt.Color;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JTextField;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class HPPanel extends PanelGeneral {
	
	private static final long serialVersionUID = 389302556444545370L;

	private int cien=70;
	
	private class HPOyente implements KeyListener{

		public void keyPressed(KeyEvent arg0) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void keyReleased(KeyEvent arg0) {
			int total=calcular(Integer.parseInt(HPM.getText()),
					Integer.parseInt(HPC.getText()));
			if (total>cien) total=cien;
			HPCB.setBounds(HPCB.getX(), HPCB.getY(), total, HPCB.getHeight());
			if (total>cien/2)
				HPCB.setBackground(Color.green);
			else if (total>cien/4)
				HPCB.setBackground(Color.yellow);
			else HPCB.setBackground(Color.red);
		}

		@Override
		public void keyTyped(KeyEvent arg0) {
			// TODO Auto-generated method stub
			
		}
		
	}
	private JTextField HPC;
	private JTextField HPM;
	private JLabel HPMB;
	private JLabel HPCB;
	
	public HPPanel() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			{
				HPC = new JTextField();
				this.add(HPC);
				HPC.setBounds(marco, marco, 30, 21);
				HPC.setText("100");
				HPC.addKeyListener(new HPOyente());
				HPC.addKeyListener(new NumListener());
			}
			{
				HPM = new JTextField();
				this.add(HPM);
				HPM.setBounds(marco+sep+30, marco, 30, 21);
				HPM.setText("100");
				HPM.addKeyListener(new HPOyente());
				HPM.addKeyListener(new NumListener());
				
			}
			{
				HPCB = new JLabel();
				this.add(HPCB);
				HPCB.setOpaque(true);
				HPCB.setBackground(Color.green);
				HPCB.setBounds(marco+1, marco+sep+21+1, cien, 10);
			}
			{
				HPMB = new JLabel();
				HPMB.setOpaque(true);
				HPMB.setBackground(Color.white);
				HPMB.setBorder(BorderFactory.createLineBorder(Color.black));
				this.add(HPMB);
				HPMB.setBounds(marco, marco+sep+21, cien+2, 12);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private int calcular(int max, int act){
		return act*cien/max;
	}

	public void Ubicar(int X, int Y) {
		this.setBounds(X,Y,marco*2+cien,marco*2+12+sep+21);
	}
}
